package com.xiaobai.netease_news.activities;

import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

import com.xiaobai.netease_news.R;
import com.xiaobai.netease_news.constants.Constant;

public class SplashActivity extends FragmentActivity implements Runnable {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);

        new Thread(this).start();
    }

    @Override
    public void run() {
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        SharedPreferences sharedPreferences = getSharedPreferences(Constant.SP_APP_NAME, MODE_PRIVATE);
        PackageManager packageManager = getPackageManager();
        int versionCode = 5;
        try {
            PackageInfo packageInfo = packageManager.getPackageInfo(getPackageName(), PackageManager.GET_ACTIVITIES);
            versionCode = packageInfo.versionCode;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        boolean isTutorialShow = sharedPreferences.getBoolean(Constant.SP_IS_TUTORIAL_SHOW + versionCode, false);
        if (isTutorialShow)
            startActivity(new Intent(this, MainActivity.class));
        else
            startActivity(new Intent(this, TutorialActivity.class));

        this.finish();
    }
}
